<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head> 
    <meta charset="UTF-8">
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <script type="text/javascript">
    
    $(document).ready(function(){
        $("#backBtn").click(function(){
            $("#showHtml").removeClass("showHtml");
            $("#confirmPage").css("display","none");
            $("#editPage").css("display","block");         
            return false;
        });
    });
    
    //子项目保存
    var checkForm={
            t:null,
            check:function(t){
                $(t).attr("disabled",true);
                this.t=t;
                if($('#subItemCd').val().trim() == $('#itemValue').val().trim()){
                        // 定制子项项目值重复，请重新输入！
                           layer.msg('<spring:message code="dictItemValueAndItmeCodeNotRepetition"/>', {time:2000}); 
                           $(checkForm.t).attr("disabled",false);
                           return;
                      }
              //获取 iframe 数量 
               	var frLength = window.parent.frames.length;
               	//父画面下标 
               	var parentIndex = frLength-2;
                // 子项值是否重复
                var result = window.parent.frames[parentIndex].isSubItemValueRepeate($('#itemValue').val(),$('#delIndex').val());
                if (result == true) {
                    
                    // 定制子项项目值重复，请重新输入！
                    layer.msg('<spring:message code="subCategoryValeRepetition"/>', {time:2000}); 
                    $(checkForm.t).attr("disabled",false);
                    return;
                    
                }
                // 表单验证
                $("#inputForm").validate({
                        // 校验是否重名
                        rules: {
                            itemValue: {remote: "${ctx}/material/category/checkName?oldItemValue=" +$("#oldItemValue").val() },
                        },
                        messages: {
                            //分类值已存在
                            itemValue: {remote: '<spring:message code="categoryItemValue_exist"/>'},
                        },
                        fail: function(element,e) {  
                              $(checkForm.t).attr("disabled",false);
                        },
                        submitHandler: function(form) {  
		                    $("#showHtml").addClass("showHtml");
		                    $("#confirmPage").css("display","block");
		                    $("#editPage").css("display","none");
		                    $(checkForm.t).attr("disabled",false);
                        }
                });
                // 提交表单
                $("#inputForm").submit(); 
            } 
        }
    
      //子项目保存
      var saveForm={
            s:null,
              t:null,
              save:function(s,t){
                  $(t).attr("disabled",true);
                  this.s=s;
                  this.t=t;
                //获取 iframe 数量 
                 	var frLength = window.parent.frames.length;
                 	//父画面下标 
                 	var parentIndex = frLength-2;
                  // 从表单中获取数据
                  var params = $("#inputForm").serialize();
                  $.post("${ctx}/material/category/saveSub", params, function(result) {
                  if (result == "false") {
                  // 重置表单
                  $("#inputForm")[0].reset();
                  $(saveForm.t).attr("disabled",false);
                  } else {
                  if(saveForm.s==1){
                      // 调用父页面方法
                      window.parent.frames[parentIndex].addItemValue();
                      // 重置表单
                      $("#inputForm")[0].reset();  
                      $(saveForm.t).attr("disabled",false);
                      $("#showHtml").removeClass("showHtml");
                      $("#confirmPage").css("display","none");
                      $("#editPage").css("display","block");   
                  }else{
                       // 刷新页面
                      window.parent.frames[parentIndex].addItemValue();
                       // 关闭
                      closeWin(); 
                   }
                   }
                  }, 'json');
              } 
      }
</script>
</head>
<body>
    <!-- 创建页面head部 -->
	<div id="editPage" class="layerHeader clearfix">
	    <!-- 新建分类子项目 -->
	     <p class="headerTitle"><spring:message code="category_createSubCategory"/></p>
	     <div class="headerButton clearfix">
	     	<shiro:hasPermission name="material:category:edit">
	        <button type="button" id="confirmBtn" onclick="checkForm.check(this)"><spring:message code="btn_ok"/></button>
	        </shiro:hasPermission>
	        <button type="button" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
	     </div>
	</div>
	
    <form id="inputForm" method="post">
        <input type="hidden" id="subItemCd" name="subItemCd" value="${category.itemCode}"/>
        <input type="hidden" id="delIndex" name="delIndex" value="${category.delIndex}"/>
		
		<!-- 确认页面head部 -->
		<div id="confirmPage" class="layerHeader clearfix" style="display:none">
			<p class="headerTitle"><spring:message code="category_confirmSubCategory"/></p>
		    <div class="headerButton clearfix">
		        <shiro:hasPermission name="material:category:edit">
		        <button type="button" id="saveBtn" onclick="saveForm.save(0,this)"><spring:message code="category_save"/></button>
		        <c:if test="${category.delIndex==-1}">
		        <button type="button" id="saveContBtn" onclick="saveForm.save(1,this)"><spring:message code="category_saveAndContinue"/></button>
		        </c:if>
		        </shiro:hasPermission>
		        <button type="button" id="backBtn"><spring:message code="material_btn_back"/></button>
		    </div>
		</div>
		
	    <div id="showHtml">
		    <div class="smList">
			    <div class="items clearfix">
			  	    <!-- 分类代码 -->
	                <p class="tit"><spring:message code="category_itemCode"/></p>
                    <p>${category.itemValue}</p>
			    </div>
			    <div class="items clearfix haveToBox">
			  	    <!-- 分类值 -->
                    <p class="tit"><spring:message code="category_show_subItemValue"/></p>
                    <input type="text"  id="itemValue" name="itemValue" value="${category.itemValue}" data-rule-lettersnumbers="true"  data-msg-lettersnumbers="<spring:message code="category_pleaseInputItemValue"/>" maxlength="22" data-msg-required="<spring:message code="category_pleaseInputSubItemValue"/>" data-rule-required="true">
                    <input type="hidden"  id="oldItemValue" name="oldItemValue" value="${category.itemValue}"/>
                    <p class="haveTo">*</p>
			    </div>
			    <div class="items clearfix haveToBox">
			  	    <!-- 分类中文名称 -->
                    <p class="tit"><spring:message code="category_show_subCn"/></p>
                    <input type="text"  id="itemNameCn" name="itemNameCn" value="${category.itemNameCn}"   maxlength="50" data-msg-required="<spring:message code="category_pleaseInputCn"/>" data-rule-required="true">
                    <p class="haveTo">*</p>
			    </div>
			    <div class="items clearfix haveToBox">
			  	    <!-- 分类英文名称 -->
                    <p class="tit"><spring:message code="category_show_subEn"/></p>
                    <input type="text"  id="itemNameEn" name="itemNameEn" value="${category.itemNameEn}"   maxlength="50" data-msg-required="<spring:message code="category_pleaseInputEn"/>" data-rule-required="true">
                    <p class="haveTo">*</p>
			    </div>
			    <div class="items clearfix">
			  	    <!-- 状态 -->
                    <p class="tit"><spring:message code="category_state"/></p>
                    <div class="clearfix labelBox">
                     <label>
                         <input type="radio" name="enableFlag" value="1" checked='checked' <c:if test="${category.enableFlag eq 1}">checked='checked'</c:if> class="rast"/><spring:message code="category_enable"/>
                     </label>
                     <label>
                         <input type="radio" id="enableFlag_check" value="0" name="enableFlag"  <c:if test="${category.enableFlag eq 0}">checked='checked'</c:if> class="rast" /><spring:message code="category_disable"/>
                     </label>
                     </div>
			    </div>
			    <div class="items clearfix">
			  	    <!-- 描述 -->
	                <p class="tit"><spring:message code="category_remarks"/>                
	                <span class="txtRg">(0/100)</span>
                    </p>
                    <textarea id="remarks" name="remarks" value="${category.remarks}"  maxlength="100">${category.remarks}</textarea>
			    </div>
		    </div>
		</div>   
	</form>
</body>
</html>